package cn.rongdao.jrkabao.ui.main.mainfragment.personal;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.mifengkong.frtools.util.FRImageLoad;
import com.mifengkong.frtools.util.FRString;

import cn.rongdao.jrkabao.R;
import cn.rongdao.jrkabao.bean.main.personal.PersonItemInfoBean;

/**
 * Created by jack on 2017/12/29
 */

public class PersonInfoUIComponent extends RelativeLayout {
    public PersonInfoUIComponent(Context context) {
        super(context);
    }

    public PersonInfoUIComponent(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public PersonInfoUIComponent(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private ImageView ivAvatar;
    private TextView tvTitle;
    private TextView tvContent;
    private View viewLine;

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        tvTitle = findViewById(R.id.lpi_tv_name);
        tvContent = findViewById(R.id.lpi_tv_right);
        ivAvatar = findViewById(R.id.lpi_iv_avatar);
        viewLine = findViewById(R.id.lpi_view_line);
    }

    public void setContent(PersonItemInfoBean data) {
        setVisibility(VISIBLE);
        tvTitle.setText(data.getConfig_cn());
        setViewLineVisible(!data.is_last_item());
        tvContent.setText(FRString.valueOf(data.getPerson_content()));
        setRightDrawable();
    }

    public void setName(String name) {
        tvTitle.setText(FRString.valueOf(name));
    }

    public void setContent(String content) {
        setVisibility(VISIBLE);
        tvContent.setText(FRString.valueOf(content));
    }

    public void setIvAvatar(String url) {
        setVisibility(VISIBLE);
        ivAvatar.setVisibility(View.VISIBLE);
        if (FRString.isEmpty(url)) {
            ivAvatar.setImageResource(R.drawable.icon_default_avatar);
        } else {
            FRImageLoad.loadCircle(url, ivAvatar, R.drawable.icon_default_avatar);
        }
        setRightDrawable();
    }

    public void setOnItemClickListener(OnClickListener onItemClickListener){
        setOnClickListener(onItemClickListener);
    }

    public void setViewLineVisible(boolean isVisible) {
        viewLine.setVisibility(isVisible ? VISIBLE : GONE);
    }

    public void setRightDrawable() {
        tvContent.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.icon_arrow_gray, 0);
    }
}
